/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package za.co.pas.spaceandtime.data;

import za.co.pas.business.data.Company;
import za.co.pas.business.data.UserLoginDetails;
import za.co.pas.business.data.Address;
import za.co.pas.business.data.Province;
import za.co.pas.business.data.Person;
import za.co.pas.business.data.Country;
import za.co.pas.business.data.UserType;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
import javax.persistence.EntityExistsException;
import org.apache.log4j.Logger;
import za.co.pas.business.abstracts.AbstractDataModel;
import za.co.pas.business.constant.Constant;
import za.co.pas.business.data.BusinessCurrency;
import za.co.pas.business.data.UserCompanyGroup;
import za.co.pas.business.data.UserGroups;
import za.co.pas.business.model.CountryDataModel;
import za.co.pas.business.model.ext.CompanyDetailModel;
import za.co.pas.business.model.ext.UserDetailModel;
import za.co.pas.business.mvc.BusinessMVC;

/**
 *
 * @author alabuschagne
 */
public class InitialData extends AbstractDataModel
{

    private CountryDataModel countryDataModel = (CountryDataModel) Constant.mvc.getModel(BusinessMVC.COUNTRY_DATA_MODEL);
    private UserDetailModel userDetailModel = (UserDetailModel) Constant.mvc.getModel(BusinessMVC.USER_DETAIL_MODEL);
    private CompanyDetailModel companyDetailModel = (CompanyDetailModel) Constant.mvc.getModel(BusinessMVC.COMPANY_DETAIL_MODEL);
    private static Logger logger = Logger.getLogger(InitialData.class);

    public UserLoginDetails CreateAll()
    {
        List<Country> countries = createCountries();
        createCurrencies(countries);
        Country SA = countryDataModel.getCountryUsingCode("ZA");
        createSAProvinces(SA);
        Address streetAddress = new Address();
        streetAddress.setCity("Randburg");
        streetAddress.setCode("2194");
        streetAddress.setCountry(SA);
        streetAddress.setLine1("234 Mahogany street");
        streetAddress.setLine2(null);
        streetAddress.setProvince(countryDataModel.getProvinceUsingCode("GP"));
        streetAddress.setSuburb("Sharonlea");
        try
        {
            persistGenericObject(streetAddress);
        }
        catch (EntityExistsException ex)
        {
            logger.error(ex.getMessage(), ex);
        }
        Address postalAddress = new Address();
        postalAddress.setCity("Randburg");
        postalAddress.setCode("2118");
        postalAddress.setCountry(SA);
        postalAddress.setLine1("PO Box 2094");
        postalAddress.setLine2(null);
        postalAddress.setProvince(countryDataModel.getProvinceUsingCode("GP"));
        postalAddress.setSuburb("Cresta");
        try
        {
            persistGenericObject(postalAddress);
        }
        catch (EntityExistsException ex)
        {
            logger.error(ex.getMessage(), ex);
        }
        Company company = new Company();
        //company.setBuildings(null);
        company.setDescription("Paranoid Android Software cc");
        company.setName("Paranoid Android Software cc");
        company.setCode(companyDetailModel.makeCompanyCode(company.getName()));
        company.setPostalAddress(postalAddress);
        company.setStreetAddress(streetAddress);
        company.setTradingAs(null);
        Person person = new Person();
        person.setCel("+27798644718");
        person.setEmail("andre@paranoidandroid.co.za");
        person.setFax(null);
        person.setFirstName("André");
        person.setPostalAddress(postalAddress);
        person.setStreetAddress(streetAddress);
        person.setSurName("Labuschagné");
        person.setTel("+27798644718");
        createUserTypes();
        createUserGroups();
        UserLoginDetails uld = new UserLoginDetails();
        uld.add(company);
        uld.setContactPerson(person);
        uld.setUserName("Tungsten15@gmail.com");
        uld.setPassword(doMD5("freya"));
        uld.setUserType(userDetailModel.getUserType("System Super User"));
        uld.setUserGroup(new UserCompanyGroup(uld, company, userDetailModel.getUserGroup("All")));
        uld.setEnabled(Boolean.TRUE);
        company.add(uld);

        
//        List<ViewAccess> va = new LinkedList<ViewAccess>();
//        va.add(new ViewAccess(CompanyDetailPanel.class.getName(), userDataModel.getUserGroup("All"), userDataModel.getUserGroup("All")));
//        va.add(new ViewAccess(CompanyListPanel.class.getName(), userDataModel.getUserGroup("All"), userDataModel.getUserGroup("All")));
//        va.add(new ViewAccess(ConfigPanel.class.getName(), userDataModel.getUserGroup("All"), userDataModel.getUserGroup("All")));
//        va.add(new ViewAccess(AddressPanel.class.getName(), userDataModel.getUserGroup("All"), userDataModel.getUserGroup("All")));
        try
        {
            userDetailModel.addUserLoginDetails(uld);
            persistGenericObject(company);
            persistGenericObject(uld);
//            persistGenericList(va);
            return uld;
        }
        catch (EntityExistsException ex)
        {
            logger.error(ex.getMessage(), ex);
        }
        catch(Exception ex)
        {
            logger.error(ex.getMessage(), ex);
            ex.printStackTrace();
        }
        return null;
    }

    private Country findCountry(List<Country> countryList, String name)
    {
        ListIterator<Country> it = countryList.listIterator();
        while (it.hasNext())
        {
            Country c = it.next();
            if (c.getName().compareToIgnoreCase(name) == 0)
            {
                return c;
            }
        }
        return null;
    }

    private void addCurrency2(List<Country> countryList,
            List<BusinessCurrency> currencyList,
            String countryName, String cName, String cCode, String cSymbol)
    {
        addCurrency(countryList, currencyList, countryName, cCode, cSymbol, cName);
    }

    private void addCurrency(List<Country> countryList,
            List<BusinessCurrency> currencyList,
            String countryName, String cCode, String cSymbol,
            String cName)
    {
        Country cc = findCountry(countryList, countryName);
        if (cc != null)
        {
            currencyList.add(new BusinessCurrency(cCode, cSymbol, cName, cc));
        }
        else
        {
            logger.warn("No currency for " + countryName);
        }
    }

    private void createCurrencies(List<Country> countryList)
    {
        List<BusinessCurrency> currencyList = new LinkedList<BusinessCurrency>();
        addCurrency(countryList, currencyList, "Albania", "ALL", "Lek", "Leke");
        addCurrency(countryList, currencyList, "Afghanistan", "AFN", "\\u060B", "Afghanis");
        addCurrency(countryList, currencyList, "Argentina", "ARS", "$", "Pesos");
        addCurrency(countryList, currencyList, "Aruba", "AWG", "\\u0192", "Guilders");
        addCurrency(countryList, currencyList, "Australia", "AUD", "$", "Dollars");
        addCurrency(countryList, currencyList, "Azerbaijan", "AZN", "\\u043c\\u0430\\u043d", "New Manats");
        addCurrency(countryList, currencyList, "Bahamas", "BSD", "$", "Dollars");
        addCurrency(countryList, currencyList, "Barbados", "BBD", "$", "Dollars");
        addCurrency(countryList, currencyList, "Belarus", "BYR", "p.", "Rubles");
        addCurrency(countryList, currencyList, "Belgium", "EUR", "\\u20ac", "Euro");
        addCurrency(countryList, currencyList, "Belize", "BZD", "BZ$", "Dollars");
        addCurrency(countryList, currencyList, "Bermuda", "BMD", "$", "Dollars");

        addCurrency(countryList, currencyList, "Bolivia", "BOB", "$b", "Bolivianos");
        addCurrency(countryList, currencyList, "Bosnia and Herzegovina", "BAM", "KM", "Convertible Marka");
        addCurrency(countryList, currencyList, "Botswana", "BWP", "P", "Pulas");
        addCurrency(countryList, currencyList, "Bulgaria", "BGN", "\\u043b\\u0432", "Leva");
        addCurrency(countryList, currencyList, "Brazil", "BRL", "R$", "Reais");
        addCurrency(countryList, currencyList, "Brunei Darussalam", "BND", "$", "Dollars");
        addCurrency(countryList, currencyList, "Cambodia", "KHR", "\\u17DB", "Riels");
        addCurrency(countryList, currencyList, "Canada", "CAD", "$", "Dollars");
        addCurrency(countryList, currencyList, "Cayman Islands", "KYD", "$", "Dollars");

        addCurrency(countryList, currencyList, "Chile", "CLP", "$", "Pesos");
        addCurrency(countryList, currencyList, "China", "CHY", "\\uA5", "Yuan Renminbi");
        addCurrency(countryList, currencyList, "Colombia", "COP", "$", "Pesos");
        addCurrency(countryList, currencyList, "Costa Rica", "CRC", "\\u20A1", "Colón");
        addCurrency(countryList, currencyList, "Croatia", "HRK", "kn", "Kuna");
        addCurrency(countryList, currencyList, "Cuba", "CUP", "\\u20B1", "Pesos");
        addCurrency(countryList, currencyList, "Cyprus", "EUR", "\\u20ac", "Euro");
        addCurrency(countryList, currencyList, "Czech Republic", "CZK", "\\u4b\\u010d", "Koruny");
        addCurrency(countryList, currencyList, "Denmark", "DKK", "kr", "Kroner");
        addCurrency(countryList, currencyList, "Dominican Republic", "DOP", "RD$", "Pesos");

        addCurrency2(countryList, currencyList, "East Caribbean", "Dollars", "XCD", "$");
        addCurrency2(countryList, currencyList, "Egypt", "Pounds", "EGP", "\\uA3");
        addCurrency2(countryList, currencyList, "El Salvador", "Colones", "SVC", "$");
        addCurrency2(countryList, currencyList, "Euro", "Euro", "EUR", "\\u20AC");
        addCurrency2(countryList, currencyList, "Falkland Islands", "Pounds", "FKP", "\\uA3");
        addCurrency2(countryList, currencyList, "Fiji", "Dollars", "FJD", "$");
        addCurrency2(countryList, currencyList, "France", "Euro", "EUR", "\\u20AC");
        addCurrency2(countryList, currencyList, "Ghana", "Cedis", "GHC", "\\uA2");
        addCurrency2(countryList, currencyList, "Gibraltar", "Pounds", "GIP", "\\uA3");
        addCurrency2(countryList, currencyList, "Greece", "Euro", "EUR", "\\u20AC");
        addCurrency2(countryList, currencyList, "Guatemala", "Quetzales", "GTQ", "Q");
        addCurrency2(countryList, currencyList, "Guernsey", "Pounds", "GGP", "\\uA3");
        addCurrency2(countryList, currencyList, "Guyana", "Dollars", "GYD", "$");
        addCurrency2(countryList, currencyList, "Honduras", "Lempiras", "HNL", "L");
        addCurrency2(countryList, currencyList, "Hong Kong", "Dollars", "HKD", "$");
        addCurrency2(countryList, currencyList, "Hungary", "Forint", "HUF", "Ft");
        addCurrency2(countryList, currencyList, "Iceland", "Kronur", "ISK", "kr");
        addCurrency2(countryList, currencyList, "India", "Rupees", "INR", "\\u20B9");
        addCurrency2(countryList, currencyList, "Indonesia", "Rupiahs", "IDR", "Rp");
        addCurrency2(countryList, currencyList, "Iran", "Rials", "IRR", "\\uFDFC");
        addCurrency2(countryList, currencyList, "Ireland", "Euro", "EUR", "\\u20AC");
        addCurrency2(countryList, currencyList, "Isle of Man", "Pounds", "IMP", "\\uA3");
        addCurrency2(countryList, currencyList, "Israel", "New Shekels", "ILS", "\\u20AA");
        addCurrency2(countryList, currencyList, "Italy", "Euro", "EUR", "\\u20AC");
        addCurrency2(countryList, currencyList, "Jamaica", "Dollars", "JMD", "J$");
        addCurrency2(countryList, currencyList, "Japan", "Yen", "JPY", "\\uA5");
        addCurrency2(countryList, currencyList, "Jersey", "Pounds", "JEP", "\\uA3");
        addCurrency2(countryList, currencyList, "Kazakhstan", "Tenge", "KZT", "\\u043B\\u0432");
        addCurrency2(countryList, currencyList, "Korea, Democratic People\"s Republic of", "Won", "KPW", "\\u20A9");
        addCurrency2(countryList, currencyList, "Korea, Republic of", "Won", "KRW", "\\u20A9");
        addCurrency2(countryList, currencyList, "Kyrgyzstan", "Soms", "KGS", "\\u043B\\u0432");
        addCurrency2(countryList, currencyList, "Laos", "Kips", "LAK", "\\u20AD");
        addCurrency2(countryList, currencyList, "Latvia", "Lati", "LVL", "Ls");
        addCurrency2(countryList, currencyList, "Lebanon", "Pounds", "LBP", "\\uA3");
        addCurrency2(countryList, currencyList, "Liberia", "Dollars", "LRD", "$");
        addCurrency2(countryList, currencyList, "Liechtenstein", "Switzerland Francs", "CHF", "CHF");
        addCurrency2(countryList, currencyList, "Lithuania", "Litai", "LTL", "Lt");
        addCurrency2(countryList, currencyList, "Luxembourg", "Euro", "EUR", "\\u20AC");
        addCurrency2(countryList, currencyList, "Macedonia", "Denars", "MKD", "\\u0434\\u0435\\u043D");
        addCurrency2(countryList, currencyList, "Malaysia", "Ringgits", "MYR", "RM");
        addCurrency2(countryList, currencyList, "Malta", "Euro", "EUR", "\\u20AC");
        addCurrency2(countryList, currencyList, "Mauritius", "Rupees", "MUR", "\\u20A8");
        addCurrency2(countryList, currencyList, "Mexico", "Pesos", "MXN", "$");
        addCurrency2(countryList, currencyList, "Mongolia", "Tugriks", "MNT", "\\u20AE");
        addCurrency2(countryList, currencyList, "Mozambique", "Meticais", "MZN", "MT");
        addCurrency2(countryList, currencyList, "Namibia", "Dollars", "NAD", "$");
        addCurrency2(countryList, currencyList, "Nepal", "Rupees", "NPR", "\\u20A8");
        addCurrency2(countryList, currencyList, "Netherlands Antilles", "Guilders", "ANG", "\\u0192");
        addCurrency2(countryList, currencyList, "Netherlands", "Euro", "EUR", "\\u20AC");
        addCurrency2(countryList, currencyList, "New Zealand", "Dollars", "NZD", "$");
        addCurrency2(countryList, currencyList, "Nicaragua", "Cordobas", "NIO", "C$");
        addCurrency2(countryList, currencyList, "Nigeria", "Nairas", "NGN", "\\u20A6");
        addCurrency2(countryList, currencyList, "Norway", "Krone", "NOK", "kr");
        addCurrency2(countryList, currencyList, "Oman", "Rials", "OMR", "\\uFDFC");
        addCurrency2(countryList, currencyList, "Pakistan", "Rupees", "PKR", "\\u20A8");
        addCurrency2(countryList, currencyList, "Panama", "Balboa", "PAB", "B/.");
        addCurrency2(countryList, currencyList, "Paraguay", "Guarani", "PYG", "Gs");
        addCurrency2(countryList, currencyList, "Peru", "Nuevos Soles", "PEN", "S/.");
        addCurrency2(countryList, currencyList, "Philippines", "Pesos", "PHP", "Php");
        addCurrency2(countryList, currencyList, "Poland", "Zlotych", "PLN", "\\u7A\\u0142");
        addCurrency2(countryList, currencyList, "Qatar", "Rials", "QAR", "\\uFDFC");
        addCurrency2(countryList, currencyList, "Romania", "New Lei", "RON", "lei");
        addCurrency2(countryList, currencyList, "Russian Federation", "Rubles", "RUB", "\\u0440\\u0443\\u0431");
        addCurrency2(countryList, currencyList, "Saint Helena", "Pounds", "SHP", "\\uA3");
        addCurrency2(countryList, currencyList, "Saudi Arabia", "Riyals", "SAR", "\\uFDFC");
        addCurrency2(countryList, currencyList, "Serbia", "Dinars", "RSD", "\\u0414\\u0438\\u043d\\u2e");
        addCurrency2(countryList, currencyList, "Seychelles", "Rupees", "SCR", "\\u20A8");
        addCurrency2(countryList, currencyList, "Singapore", "Dollars", "SGD", "$");
        addCurrency2(countryList, currencyList, "Slovenia", "Euro", "EUR", "\\u20AC");
        addCurrency2(countryList, currencyList, "Solomon Islands", "Dollars", "SBD", "$");
        addCurrency2(countryList, currencyList, "Somalia", "Shillings", "SOS", "S");
        addCurrency2(countryList, currencyList, "South Africa", "Rand", "ZAR", "R");
        addCurrency2(countryList, currencyList, "Spain", "Euro", "EUR", "\\u20AC");
        addCurrency2(countryList, currencyList, "Sri Lanka", "Rupees", "LKR", "\\u20A8");
        addCurrency2(countryList, currencyList, "Sweden", "Kronor", "SEK", "kr");
        addCurrency2(countryList, currencyList, "Switzerland", "Francs", "CHF", "CHF");
        addCurrency2(countryList, currencyList, "Suriname", "Dollars", "SRD", "$");
        addCurrency2(countryList, currencyList, "Syria", "Pounds", "SYP", "\\uA3");
        addCurrency2(countryList, currencyList, "Taiwan", "New Dollars", "TWD", "NT$");
        addCurrency2(countryList, currencyList, "Thailand", "Baht", "THB", "\\u0E3F");
        addCurrency2(countryList, currencyList, "Trinidad and Tobago", "Dollars", "TTD", "TT$");
        addCurrency2(countryList, currencyList, "Turkey", "Lira", "TRY", "TL");
        addCurrency2(countryList, currencyList, "Tuvalu", "Dollars", "TVD", "$");
        addCurrency2(countryList, currencyList, "Ukraine", "Hryvnia", "UAH", "\\u20B4");
        addCurrency2(countryList, currencyList, "United Kingdom", "Pounds", "GBP", "\\uA3");
        addCurrency(countryList, currencyList, "United States", "USD", "$", "Dollars");
        addCurrency2(countryList, currencyList, "Uruguay", "Pesos", "UYU", "$U");
        addCurrency2(countryList, currencyList, "Uzbekistan", "Sums", "UZS", "\\u043B\\u0432");
        addCurrency2(countryList, currencyList, "Vatican City", "Euro", "EUR", "\\u20AC");
        addCurrency2(countryList, currencyList, "Venezuela", "Bolivares Fuertes", "VEF", "Bs");
        addCurrency2(countryList, currencyList, "Vietnam", "Dong", "VND", "\\u20AB");
        addCurrency2(countryList, currencyList, "Yemen", "Rials", "YER", "\\uFDFC");
        addCurrency2(countryList, currencyList, "Zimbabwe", "Zimbabwe Dollars", "ZWD", "Z$");

        try
        {
            persistGenericList(currencyList);
        }
        catch (EntityExistsException ex)
        {
            logger.error(ex.getMessage(), ex);
        }
    }

    private List<Country> createCountries()
    {
        List<Country> countryList = new LinkedList<Country>();
        countryList.add(new Country("AF", "Afghanistan"));
        countryList.add(new Country("AX", "Åland Islands"));
        countryList.add(new Country("AL", "Albania"));
        countryList.add(new Country("DZ", "Algeria"));
        countryList.add(new Country("AS", "American Samoa"));
        countryList.add(new Country("AD", "Andorra"));
        countryList.add(new Country("AO", "Angola"));
        countryList.add(new Country("AI", "Anguilla"));
        countryList.add(new Country("AQ", "Antarctica"));
        countryList.add(new Country("AG", "Antigua and Barbuda"));
        countryList.add(new Country("AR", "Argentina"));
        countryList.add(new Country("AM", "Armenia"));
        countryList.add(new Country("AW", "Aruba"));
        countryList.add(new Country("AU", "Australia"));
        countryList.add(new Country("AT", "Austria"));
        countryList.add(new Country("AZ", "Azerbaijan"));
        countryList.add(new Country("BS", "Bahamas"));
        countryList.add(new Country("BH", "Bahrain"));
        countryList.add(new Country("BD", "Bangladesh"));
        countryList.add(new Country("BB", "Barbados"));
        countryList.add(new Country("BY", "Belarus"));
        countryList.add(new Country("BE", "Belgium"));
        countryList.add(new Country("BZ", "Belize"));
        countryList.add(new Country("BJ", "Benin"));
        countryList.add(new Country("BM", "Bermuda"));
        countryList.add(new Country("BT", "Bhutan"));
        countryList.add(new Country("BO", "Bolivia"));
        countryList.add(new Country("BA", "Bosnia and Herzegovina"));
        countryList.add(new Country("BW", "Botswana"));
        countryList.add(new Country("BV", "Bouvet Island"));
        countryList.add(new Country("BR", "Brazil"));
        countryList.add(new Country("IO", "British Indian Ocean Territory"));
        countryList.add(new Country("BN", "Brunei Darussalam"));
        countryList.add(new Country("BG", "Bulgaria"));
        countryList.add(new Country("BF", "Burkina Faso"));
        countryList.add(new Country("BI", "Burundi"));
        countryList.add(new Country("KH", "Cambodia"));
        countryList.add(new Country("CM", "Cameroon"));
        countryList.add(new Country("CA", "Canada"));
        countryList.add(new Country("CV", "Cape Verde"));
        countryList.add(new Country("KY", "Cayman Islands"));
        countryList.add(new Country("CF", "Central African Republic"));
        countryList.add(new Country("TD", "Chad"));
        countryList.add(new Country("CL", "Chile"));
        countryList.add(new Country("CN", "China"));
        countryList.add(new Country("CX", "Christmas Island"));
        countryList.add(new Country("CC", "Cocos (Keeling) Islands"));
        countryList.add(new Country("CO", "Colombia"));
        countryList.add(new Country("KM", "Comoros"));
        countryList.add(new Country("CG", "Congo"));
        countryList.add(new Country("CD", "Congo, The Democratic Republic of the"));
        countryList.add(new Country("CK", "Cook Islands"));
        countryList.add(new Country("CR", "Costa Rica"));
        countryList.add(new Country("CI", "C�te D\"Ivoire"));
        countryList.add(new Country("HR", "Croatia"));
        countryList.add(new Country("CU", "Cuba"));
        countryList.add(new Country("CY", "Cyprus"));
        countryList.add(new Country("CZ", "Czech Republic"));
        countryList.add(new Country("DK", "Denmark"));
        countryList.add(new Country("DJ", "Djibouti"));
        countryList.add(new Country("DM", "Dominica"));
        countryList.add(new Country("DO", "Dominican Republic"));
        countryList.add(new Country("EC", "Ecuador"));
        countryList.add(new Country("EG", "Egypt"));
        countryList.add(new Country("SV", "El Salvador"));
        countryList.add(new Country("GQ", "Equatorial Guinea"));
        countryList.add(new Country("ER", "Eritrea"));
        countryList.add(new Country("EE", "Estonia"));
        countryList.add(new Country("ET", "Ethiopia"));
        countryList.add(new Country("FK", "Falkland Islands"));
        countryList.add(new Country("FO", "Faroe Islands"));
        countryList.add(new Country("FJ", "Fiji"));
        countryList.add(new Country("FI", "Finland"));
        countryList.add(new Country("FR", "France"));
        countryList.add(new Country("GF", "French Guiana"));
        countryList.add(new Country("PF", "French Polynesia"));
        countryList.add(new Country("TF", "French Southern Territories"));
        countryList.add(new Country("GA", "Gabon"));
        countryList.add(new Country("GM", "Gambia"));
        countryList.add(new Country("GE", "Georgia"));
        countryList.add(new Country("DE", "Germany"));
        countryList.add(new Country("GH", "Ghana"));
        countryList.add(new Country("GI", "Gibraltar"));
        countryList.add(new Country("GR", "Greece"));
        countryList.add(new Country("GL", "Greenland"));
        countryList.add(new Country("GD", "Grenada"));
        countryList.add(new Country("GP", "Guadeloupe"));
        countryList.add(new Country("GU", "Guam"));
        countryList.add(new Country("GT", "Guatemala"));
        countryList.add(new Country("GG", "Guernsey"));
        countryList.add(new Country("GN", "Guinea"));
        countryList.add(new Country("GW", "Guinea-Bissau"));
        countryList.add(new Country("GY", "Guyana"));
        countryList.add(new Country("HT", "Haiti"));
        countryList.add(new Country("HM", "Heard Island and McDonald Islands"));
        countryList.add(new Country("VA", "Holy See (Vatican City State)"));
        countryList.add(new Country("HN", "Honduras"));
        countryList.add(new Country("HK", "Hong Kong"));
        countryList.add(new Country("HU", "Hungary"));
        countryList.add(new Country("IS", "Iceland"));
        countryList.add(new Country("IN", "India"));
        countryList.add(new Country("ID", "Indonesia"));
        countryList.add(new Country("IR", "Iran, Islamic Republic of"));
        countryList.add(new Country("IQ", "Iraq"));
        countryList.add(new Country("IE", "Ireland"));
        countryList.add(new Country("IM", "Isle of Man"));
        countryList.add(new Country("IL", "Israel"));
        countryList.add(new Country("IT", "Italy"));
        countryList.add(new Country("JM", "Jamaica"));
        countryList.add(new Country("JP", "Japan"));
        countryList.add(new Country("JE", "Jersey"));
        countryList.add(new Country("JO", "Jordan"));
        countryList.add(new Country("KZ", "Kazakhstan"));
        countryList.add(new Country("KE", "Kenya"));
        countryList.add(new Country("KI", "Kiribati"));
        countryList.add(new Country("KP", "Korea, Democratic People\"s Republic of"));
        countryList.add(new Country("KR", "Korea, Republic of"));
        countryList.add(new Country("KW", "Kuwait"));
        countryList.add(new Country("KG", "Kyrgyzstan"));
        countryList.add(new Country("LA", "Lao People\"s Democratic Republic"));
        countryList.add(new Country("LV", "Latvia"));
        countryList.add(new Country("LB", "Lebanon"));
        countryList.add(new Country("LS", "Lesotho"));
        countryList.add(new Country("LR", "Liberia"));
        countryList.add(new Country("LY", "Libyan Arab Jamahiriya"));
        countryList.add(new Country("LI", "Liechtenstein"));
        countryList.add(new Country("LT", "Lithuania"));
        countryList.add(new Country("LU", "Luxembourg"));
        countryList.add(new Country("MO", "Macao"));
        countryList.add(new Country("MK", "Macedonia, The Former Yugoslav Republic of"));
        countryList.add(new Country("MG", "Madagascar"));
        countryList.add(new Country("MW", "Malawi"));
        countryList.add(new Country("MY", "Malaysia"));
        countryList.add(new Country("MV", "Maldives"));
        countryList.add(new Country("ML", "Mali"));
        countryList.add(new Country("MT", "Malta"));
        countryList.add(new Country("MH", "Marshall Islands"));
        countryList.add(new Country("MQ", "Martinique"));
        countryList.add(new Country("MR", "Mauritania"));
        countryList.add(new Country("MU", "Mauritius"));
        countryList.add(new Country("YT", "Mayotte"));
        countryList.add(new Country("MX", "Mexico"));
        countryList.add(new Country("FM", "Micronesia, Federated States of"));
        countryList.add(new Country("MD", "Moldova, Republic of"));
        countryList.add(new Country("MC", "Monaco"));
        countryList.add(new Country("MN", "Mongolia"));
        countryList.add(new Country("ME", "Montenegro"));
        countryList.add(new Country("MS", "Montserrat"));
        countryList.add(new Country("MA", "Morocco"));
        countryList.add(new Country("MZ", "Mozambique"));
        countryList.add(new Country("MM", "Myanmar"));
        countryList.add(new Country("NA", "Namibia"));
        countryList.add(new Country("NR", "Nauru"));
        countryList.add(new Country("NP", "Nepal"));
        countryList.add(new Country("NL", "Netherlands"));
        countryList.add(new Country("AN", "Netherlands Antilles"));
        countryList.add(new Country("NC", "New Caledonia"));
        countryList.add(new Country("NZ", "New Zealand"));
        countryList.add(new Country("NI", "Nicaragua"));
        countryList.add(new Country("NE", "Niger"));
        countryList.add(new Country("NG", "Nigeria"));
        countryList.add(new Country("NU", "Niue"));
        countryList.add(new Country("NF", "Norfolk Island"));
        countryList.add(new Country("MP", "Northern Mariana Islands"));
        countryList.add(new Country("NO", "Norway"));
        countryList.add(new Country("OM", "Oman"));
        countryList.add(new Country("PK", "Pakistan"));
        countryList.add(new Country("PW", "Palau"));
        countryList.add(new Country("PS", "Palestinian Territory, Occupied"));
        countryList.add(new Country("PA", "Panama"));
        countryList.add(new Country("PG", "Papua New Guinea"));
        countryList.add(new Country("PY", "Paraguay"));
        countryList.add(new Country("PE", "Peru"));
        countryList.add(new Country("PH", "Philippines"));
        countryList.add(new Country("PN", "Pitcairn"));
        countryList.add(new Country("PL", "Poland"));
        countryList.add(new Country("PT", "Portugal"));
        countryList.add(new Country("PR", "Puerto Rico"));
        countryList.add(new Country("QA", "Qatar"));
        countryList.add(new Country("RE", "Reunion"));
        countryList.add(new Country("RO", "Romania"));
        countryList.add(new Country("RU", "Russian Federation"));
        countryList.add(new Country("RW", "Rwanda"));
        countryList.add(new Country("BL", "Saint Barth�lemy"));
        countryList.add(new Country("SH", "Saint Helena"));
        countryList.add(new Country("KN", "Saint Kitts and Nevis"));
        countryList.add(new Country("LC", "Saint Lucia"));
        countryList.add(new Country("MF", "Saint Martin"));
        countryList.add(new Country("PM", "Saint Pierre and Miquelon"));
        countryList.add(new Country("VC", "Saint Vincent and the Grenadines"));
        countryList.add(new Country("WS", "Samoa"));
        countryList.add(new Country("SM", "San Marino"));
        countryList.add(new Country("ST", "Sao Tome and Principe"));
        countryList.add(new Country("SA", "Saudi Arabia"));
        countryList.add(new Country("SN", "Senegal"));
        countryList.add(new Country("RS", "Serbia"));
        countryList.add(new Country("SC", "Seychelles"));
        countryList.add(new Country("SL", "Sierra Leone"));
        countryList.add(new Country("SG", "Singapore"));
        countryList.add(new Country("SK", "Slovakia"));
        countryList.add(new Country("SI", "Slovenia"));
        countryList.add(new Country("SB", "Solomon Islands"));
        countryList.add(new Country("SO", "Somalia"));
        countryList.add(new Country("ZA", "South Africa"));
        countryList.add(new Country("GS", "South Georgia and the South Sandwich Islands"));
        countryList.add(new Country("ES", "Spain"));
        countryList.add(new Country("LK", "Sri Lanka"));
        countryList.add(new Country("SD", "Sudan"));
        countryList.add(new Country("SR", "Suriname"));
        countryList.add(new Country("SJ", "Svalbard and Jan Mayen"));
        countryList.add(new Country("SZ", "Swaziland"));
        countryList.add(new Country("SE", "Sweden"));
        countryList.add(new Country("CH", "Switzerland"));
        countryList.add(new Country("SY", "Syrian Arab Republic"));
        countryList.add(new Country("TW", "Taiwan, Province Of China"));
        countryList.add(new Country("TJ", "Tajikistan"));
        countryList.add(new Country("TZ", "Tanzania, United Republic of"));
        countryList.add(new Country("TH", "Thailand"));
        countryList.add(new Country("TL", "Timor-Leste"));
        countryList.add(new Country("TG", "Togo"));
        countryList.add(new Country("TK", "Tokelau"));
        countryList.add(new Country("TO", "Tonga"));
        countryList.add(new Country("TT", "Trinidad and Tobago"));
        countryList.add(new Country("TN", "Tunisia"));
        countryList.add(new Country("TR", "Turkey"));
        countryList.add(new Country("TM", "Turkmenistan"));
        countryList.add(new Country("TC", "Turks and Caicos Islands"));
        countryList.add(new Country("TV", "Tuvalu"));
        countryList.add(new Country("UG", "Uganda"));
        countryList.add(new Country("UA", "Ukraine"));
        countryList.add(new Country("AE", "United Arab Emirates"));
        countryList.add(new Country("GB", "United Kingdom"));
        countryList.add(new Country("US", "United States"));
        countryList.add(new Country("UM", "United States Minor Outlying Islands"));
        countryList.add(new Country("UY", "Uruguay"));
        countryList.add(new Country("UZ", "Uzbekistan"));
        countryList.add(new Country("VU", "Vanuatu"));
        countryList.add(new Country("VE", "Venezuela"));
        countryList.add(new Country("VN", "Viet Nam"));
        countryList.add(new Country("VG", "Virgin Islands, British"));
        countryList.add(new Country("VI", "Virgin Islands, U.S."));
        countryList.add(new Country("WF", "Wallis And Futuna"));
        countryList.add(new Country("EH", "Western Sahara"));
        countryList.add(new Country("YE", "Yemen"));
        countryList.add(new Country("ZM", "Zambia"));
        countryList.add(new Country("ZW", "Zimbabwe"));
        try
        {
            persistGenericList(countryList);
        }
        catch (EntityExistsException ex)
        {
            logger.error(ex.getMessage(), ex);
        }
        return countryList;
    }

    private void createSAProvinces(Country country)
    {
        List<Province> provinces = new LinkedList<Province>();
        provinces.add(new Province(country, "EC", "Eastern Cape"));
        provinces.add(new Province(country, "FS", "Free State"));
        provinces.add(new Province(country, "GP", "Gauteng"));
        provinces.add(new Province(country, "ZN", "KwaZulu Natal"));
        provinces.add(new Province(country, "LP", "Limpopo"));
        provinces.add(new Province(country, "MP", "Mpumalanga"));
        provinces.add(new Province(country, "NC", "Northern Cape"));
        provinces.add(new Province(country, "NW", "North West"));
        provinces.add(new Province(country, "WC", "Western Cape"));
        country.setProvinces(provinces);
        try
        {
            persistGenericList(provinces);
            persistGenericObject(country);
        }
        catch (EntityExistsException ex)
        {
            logger.error(ex.getMessage(), ex);
        }
    }

    private void createUserTypes()
    {
        List<UserType> userTypes = new LinkedList<UserType>();
        userTypes.add(new UserType("System Super User", 0));
        userTypes.add(new UserType("System User", 1));
        userTypes.add(new UserType("Company Super User", 2));
        userTypes.add(new UserType("User", 3));
        try
        {
            persistGenericList(userTypes);
        }
        catch (EntityExistsException ex)
        {
            logger.error(ex.getMessage(), ex);
        }
    }

    private void createUserGroups()
    {
        List<UserGroups> userGroups = new LinkedList<UserGroups>();
        userGroups.add(new UserGroups("All"));
        userGroups.add(new UserGroups("Back-end"));
        userGroups.add(new UserGroups("Front-end"));
        try
        {
            persistGenericList(userGroups);
        }
        catch (EntityExistsException ex)
        {
            logger.error(ex.getMessage(), ex);
        }
    }
}
